<?php

session_start();
include("db_connect.php");

$pid= mysql_real_escape_string(htmlentities(trim($_GET['pid']))); 
$types =mysql_real_escape_string(htmlentities(trim($_GET['types'])));

if($types == "edit" ){
$name = mysql_real_escape_string(htmlentities(trim($_GET['name'])));
$description = mysql_real_escape_string(htmlentities(trim($_GET['description'])));
$condition = mysql_real_escape_string(htmlentities(trim($_GET['condition'])));
$fuel = mysql_real_escape_string(htmlentities(trim($_GET['fuel'])));
$transmission = mysql_real_escape_string(htmlentities(trim($_GET['transmission'])));
$ctype = mysql_real_escape_string(htmlentities(trim($_GET['ctype'])));
$price = mysql_real_escape_string(htmlentities(trim($_GET['price'])));
$quantity = mysql_real_escape_string(htmlentities(trim($_GET['quantity'])));
$category = mysql_real_escape_string(htmlentities(trim($_GET['category'])));

edit($pid,$name,$description,$condition,$fuel,$transmission,$ctype,$price,$quantity,$category);
}
else{
$name = mysql_real_escape_string(htmlentities(trim($_GET['name'])));
$description = mysql_real_escape_string(htmlentities(trim($_GET['description'])));



$ctype = mysql_real_escape_string(htmlentities(trim($_GET['ctype'])));
$price = mysql_real_escape_string(htmlentities(trim($_GET['price'])));
$quantity = mysql_real_escape_string(htmlentities(trim($_GET['quantity'])));
$category = mysql_real_escape_string(htmlentities(trim($_GET['category'])));

edited($pid,$name,$description,$ctype,$price,$quantity,$category);

}

function edit($pid,$name,$description,$condition,$fuel,$transmission,$ctype,$price,$quantity,$category){
	$sql= "UPDATE tblswaping SET name = '".$name."', description = '".$description."', conditions = '".$condition."',  fuel = '".$fuel."', transmission = '".$transmission."', types = '".$ctype."', price = '".$price."', quantity = '".$quantity."', categories = '".$category."'  WHERE id = '".$pid."' ";
	mysql_query($sql) or die(mysql_error());
	if (mysql_affected_rows()){		
		echo "1";
	}
	else{		
		echo $sql;
	}
}


function edited($pid,$name,$description,$ctype,$price,$quantity,$category){
	$sql= "UPDATE tblswaping SET name = '".$name."', description = '".$description."', types = '".$ctype."', price = '".$price."', quantity = '".$quantity."', categories = '".$category."'  WHERE id = '".$pid."' ";
	mysql_query($sql) or die(mysql_error());
	if (mysql_affected_rows()){		
		echo "1";
	}
	else{		
		echo $sql;
	}
}

?>

